﻿using System;
using System.IO;
using System.Text;

namespace AutoUnitTestEngine.Helpers
{
    public class TextOutputHelper
    {
        public static void OutputTextFile(string filePath,string context)
        {
            var sw = new StreamWriter(filePath);
            try
            {
                sw.Write(context);
            }
            finally
            {
                sw.Close();
                sw.Dispose();
            }
        }

        public static void OutputExceptionTextFile(string filePath, Exception exObj)
        {
            var sbContext = new StringBuilder(exObj.Message);
            sbContext.Append("\r\n\r\n\r\n");
            sbContext.Append(exObj.Source);
            sbContext.Append("\r\n\r\n\r\n");
            sbContext.Append(exObj.StackTrace);
            sbContext.Append("\r\n\r\n\r\n");
            OutputTextFile(filePath, sbContext.ToString());
        }
    }
}
